package com.tongna.controller;

import com.tongna.domain.Tenant;
import com.tongna.service.TenantService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

/**
 * TenantDemo
 *
 * @author 张浩伟
 * @version 1.01 2018年02月09日
 */
@Controller
@RequestMapping("tenant")
public class TenantController {

    @Autowired
    private TenantService service;

    @GetMapping("list")
    public String list(Model model){
        model.addAttribute("list", service.findAll());
        return "tenant/list";
    }

    @GetMapping("add")
    public String add(Model model){
        return "tenant/add";
    }

    @PostMapping("add")
    public String add(Tenant tenant){
        service.add(tenant);
        return "redirect:/tenant/list";
    }

}
